<template>
  <div>
    <ButtonGroup shape="circle">
        <Button type="ghost" v-for="(item,index) in this.$store.state.app.buttons" v-if="item.parentId === menuId" :key="index" :icon="item.icon" @click="events(item)">
            {{item.title}}
        </Button>
    </ButtonGroup>
  </div>
</template>

<script>
    export default {
        props: {
            menuId: {
                type: Number,
                default: ''
            }
        },
        data () {
            return {
                baseURL: '/user/buttons',
                buttons: []
            }
        },
        methods: {
            events (item) {
                this.$emit('events',item)
            },
            init () {
                if (this.menuId > 0) {
                    let url = this.baseURL + '/' + this.menuId
                    this.$ajax.get(url).then((response) => {
                        let {code, data, msg} = response.data
                        if (code === 0) {
                            this.buttons = data
                        } else {
                            this.$bus.alert('error', msg)
                        }
                    })
                }
            },
            refresh () {
                let url = this.baseURL + '/' + this.menuId
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.buttons = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            }
        },
        mounted () {
            // this.init()
        }
    }
</script>

<style>

</style>
